package com.sdp.core.bizc.listener;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Service;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Service
public class SysListener implements ApplicationListener<ApplicationEvent>{
	
	@Autowired
	private CacheListener cacheListener;
	
	
	@Override
	public void onApplicationEvent(ApplicationEvent event) {
		
		//保证只执行一次
//		if (event.getApplicationContext().getParent() == null) {
//			ApplicationContextUtils.setContext(event.getApplicationContext());
//			//获得cache注解对应的信息
//			cacheListener.getCacheKeysWithAnnotation(event);
//		}
		if (event instanceof ApplicationStartedEvent) {
			log.info("------------------init cache-------------------");
//			//初始化bean的静态工具类
//			ApplicationContextUtils.setContext(((ApplicationStartedEvent) event).getApplicationContext());
			//获得cache注解对应的信息
			cacheListener.getCacheKeysWithAnnotation(((ApplicationStartedEvent) event).getApplicationContext());
			
		}
		
	}

}
